package com.gc.frontend.web.action.ajax;

import com.alibaba.fastjson.JSONObject;
import com.gc.frontend.service.MessageService;
import com.gc.common.util.ReturnJsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created by 瑱彬 on 2015/5/5.
 */
@Controller
@RequestMapping("/ajax/message")
public class MessageController {
    @Autowired
    MessageService messageService;

    @RequestMapping("/getUnread")
    @ResponseBody
    public JSONObject getUnread() {
        List<Map<String, Object>> messages = this.messageService.selectUnread();
        return ReturnJsonUtil.successRows(messages);
    }

    @RequestMapping("/read")
    @ResponseBody
    public JSONObject read(Integer messageId) {
        this.messageService.markRead(messageId);
        return ReturnJsonUtil.successMsg("更新成功");
    }

}
